<?php
$txtHoten=replatestring($_POST[txtHoten],false);

$kh_id=$_POST['kh_id'];
$Kha_Id=$_POST['Kha_Id'];
if($Kha_Id==""){$Kha_Id=$kh_id;}

$Dml_Id=$_POST['Dml_Id'];
$sanphamsudung=$_POST['sanphamsudung'];
$sanphamsudung_id=$_POST['sanphamsudung_id'];
if($sanphamsudung_id==""){$sanphamsudung_id=$sanphamsudung;}
$mota=replatestring($_POST[mota],false);
$doanhthu=replatestring($_POST[doanhthu],false);
$thanhcong=replatestring($_POST[thanhcong],false);
$danhgia=replatestring($_POST[danhgia],false);
$ngayketthuc=replatestring($_POST[ngayketthuc],false);
$IDNguongoc=replatestring($_POST[IDNguongoc],false);
$idmkt=$_POST['market'];
$marketing_id=replatestring($_POST[marketing_id],false);
if($marketing_id==""){$marketing_id=$idmkt;}
$dexuat=replatestring($_POST[dexuat],false);
$donviquanly=$_POST['donviquanly'];
$txtNguoiquanly=$_POST['txtNguoiquanly'];

$txtNguoitao=$_SESSION['userid'];
$txtNgaytao=time();
$txtnguoisua=$_SESSION['userid'];
$txtNgaycapnhat=time();
$txtnoidung=$_POST['txtnoidung'];

$id=replatestring($_POST[ch_id],false);
$soanh=$_POST['hdnsoanh'];
$hinhanhsp = "";
for($i=1;$i<=$soanh;$i++){
	if($i<$soanh)$hinhanhsp .= $_POST["sanpham_hinhanh".$i]."~";
	else $hinhanhsp .= $_POST["sanpham_hinhanh".$i];
}
$date=time();
$nguoiql=$_POST['nguoiql'];
$Nguoi_Quan_Ly_Khac=$_POST['Nguoi_Quan_Ly_Khac'];	
if($Nguoi_Quan_Ly_Khac==""){$Nguoi_Quan_Ly_Khac=$nguoiql;}
$data=false;
if($txtHoten!==""){$data=true;}

if($data==true){
	if($id==""){
		mysql_query("insert into cohoi 
(name,kh_id,dmll_id,product_id,description,doanhthu,thanhcong,danhgia,end_time,nguongoc,marketing,dexuat,manager_unit,manager,manager_other,creater,creat_time,user_edit,update_time,file_attach)
		value('$txtHoten','$Kha_Id','$Dml_Id','$sanphamsudung_id','$mota','$doanhthu','$thanhcong','$danhgia','$ngayketthuc','$IDNguongoc','$marketing_id','$dexuat','$donviquanly','$txtNguoiquanly','$Nguoi_Quan_Ly_Khac','$txtNguoitao','$date','$txtnguoisua','$date','$hinhanhsp')
		");
		
	
		$cauthongbao="Thêm thành công";
		$link=$url_main_site."system/index.php?tn=customers&kh=cohoi_list";
		thongbao($cauthongbao,$link);			

	}
	else
	{
			mysql_query("
					update cohoi set 
						name='$txtHoten',
						kh_id='$Kha_Id',
						dmll_id='$Dml_Id',
						product_id='$sanphamsudung_id',
						description='$mota',
						doanhthu='$doanhthu',
						thanhcong='$thanhcong',
						danhgia='$danhgia',
						end_time='$ngayketthuc',
						nguongoc='$IDNguongoc',
						marketing='$marketing_id',
						dexuat='$dexuat',					
						manager_unit='$donviquanly',
						manager='$txtNguoiquanly',
						manager_other='$Nguoi_Quan_Ly_Khac',
						user_edit='$txtnguoisua',
						update_time='$date'
					
					where id='$id'
			");
			if($hinhanhsp!="")
			{
			mysql_query("update cohoi set file_attach='$hinhanhsp' where id='$id'");
			}
			$cauthongbao="Bạn đã sửa thành công";
			$link=$url_main_site."system/index.php?tn=customers&kh=cohoi_list";
			thongbao($cauthongbao,$link);	

	}
}
else
{
		$cauthongbao="Dữ liệu không hợp lệ";
		$link=$url_main_site."system/index.php?tn=customers&kh=cohoi_list";
		thongbao($cauthongbao,$link);
}
?>